let JSDOM = require('jsdom').JSDOM
let {readFile} = require('fs')
let {resolve} = require('path')

function html2$(html) {
    let document = new JSDOM(html).window.document
    return document.querySelectorAll.bind(document)
}

readFile(resolve('../tmp/shouji.html'), (err, buffer) => {
    if (err) {
        console.log(err)
    } else {
        let $ = html2$(html2$(buffer.toString())('textarea.f1')[0].value)
        let dates = Array.from($('li')).map(li => {
            let oA = li.getElementsByClassName('mod-g-photo')[0]
            return {
                url: 'http:' + oA.href,
                img_src: 'http:' + oA.children[0].getAttribute('data-lazyload-src'),
                name: li.getElementsByClassName('mod-g-tit')[0].children[0].text,
                description: li.getElementsByClassName('mod-g-desc')[0].innerHTML,
                // price: li.getElementsByClassName('mod-g-nprice')[0].innerHTML.match(/\d+(\.\d+)?/g)[0],
                sales: li.getElementsByClassName('mod-g-sales')[0].innerHTML.match(/(\d+)/)[0]
            }
        })
        console.log(dates)
    }
})